from fastapi import APIRouter

from app.database.postgre import SessionDep
from app.models.common import AppIdParams, DeviceIdJSON, AppIdJSON
from app.models.devices import AppDeviceListParams, BatchDeleteAppDevicesJSON, DeviceCardsListParams
from app.services import accounts, devices

router = APIRouter(
    prefix='/api/v1/devices',
    tags=['backend', 'devices']
)


@router.get('/list')
async def devices_list(account: accounts.LoggedInAccount, query_params: AppDeviceListParams, session: SessionDep):
    response = await devices.get_devices_list(account, query_params, session)
    return response


@router.get('/used_cards')
async def device_used_cards(account: accounts.LoggedInAccount, query_params: DeviceCardsListParams, session: SessionDep):
    response = await devices.get_device_used_cards(account, query_params, session)
    return response


@router.post('/delete')
async def delete_device(account: accounts.LoggedInAccount, json_data: DeviceIdJSON, session: SessionDep):
    response = await devices.delete_device_by_id(account, json_data, session)
    return response


@router.post('/batch_delete')
async def batch_delete_devices(account: accounts.LoggedInAccount, json_data: BatchDeleteAppDevicesJSON,
                               session: SessionDep):
    response = await devices.delete_device_by_ids(account, json_data, session)
    return response


@router.post('/clear')
async def clear_app_devices(account: accounts.LoggedInAccount, json_data: AppIdJSON, session: SessionDep):
    response = await devices.clear_all_app_devices(account, json_data, session)
    return response


@router.post('/logout')
async def device_logout(account: accounts.LoggedInAccount, json_data: DeviceIdJSON, session: SessionDep):
    response = await devices.logout_device(account, json_data, session)
    return response


@router.get('/online_count')
async def devices_online_count(account: accounts.LoggedInAccount, query_params: AppIdParams, session: SessionDep):
    response = await devices.get_devices_online_count(account, query_params, session)
    return response
